package test;

import java.io.*;

public class BufferedSteamDemo {
    //字节缓冲流
    //字节缓冲流是字节输入流和字节输出流的缓冲区
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        try(
                FileInputStream fileInputStream = new FileInputStream("demo17\\src\\test\\1.jpg");
                BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                FileOutputStream fileOutputStream = new FileOutputStream(ifFile("demo17\\src\\test\\2.jpg"));
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream)
        ) {

            byte[] buf = new byte[1024];
            int len2;
            while((len2 = bufferedInputStream.read(buf) ) != -1) {
//			    System.out.println(new String(buf, 0, len2));
                bufferedOutputStream.write(buf,0,len2);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间：" + (endTime - startTime) + "ms" );

    }

    public static File ifFile(String path) {
        File file = new File(path);
        if(!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return file;
    }


}
